package com.thingple.web;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.thingple.h5.bridge.JsInvokeHandler;
import com.thingple.h5.webclient.JsBridgeWebViewClient;
import com.thingple.web.bridge.location.LocationJsBridgeImpl;
import com.thingple.web.bridge.message.MessageJsBridgeImpl;
import com.thingple.web.bridge.printer.PrinterJsBridgeImpl;
import com.thingple.web.bridge.reader.InventoryJsBridgeImpl;
import com.thingple.web.bridge.reader.ReaderJsBridgeImpl;
import com.thingple.web.bridge.settings.SettingsJsBridgeImpl;
import com.thingple.web.bridge.view.ViewJsBridgeImpl;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * Created by lism on 2017/7/10.
 */
public abstract class WebViewActivity extends com.thingple.h5.CommonWebPageActivity {

    private boolean paused = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initWebViewClient(JsBridgeWebViewClient client) {
        client
                .registerBridge(MessageJsBridgeImpl.class)
                .registerBridge(ViewJsBridgeImpl.class)
                .registerBridge(InventoryJsBridgeImpl.class)
                .registerBridge(ReaderJsBridgeImpl.class)
                .registerBridge(SettingsJsBridgeImpl.class)
                .registerBridge(LocationJsBridgeImpl.class)
                .registerBridge(PrinterJsBridgeImpl.class)
        ;
    }

    @Override
    protected void onPause() {
        paused = true;
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (paused) {
            paused = false;
            JsInvokeHandler jsInvokeHandler = new JsInvokeHandler(getWebView());
            String module = "window";
            String function = "onResume";
            Map<String, String> params = new HashMap<>();
            jsInvokeHandler.module(module)
                    .function(function)
                    .params(params)
                    .invoke();
        }
    }
}
